package com.yyj.controller;

import com.github.pagehelper.PageInfo;
import com.yyj.entity.Audit;
import com.yyj.entity.Params;
import com.yyj.entity.Pet;
import com.yyj.entity.Result;
import com.yyj.service.AuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "http://localhost:8081", methods = {RequestMethod.POST, RequestMethod.GET})
@RestController
@RequestMapping
public class AuditController {
    @Autowired
    AuditService auditService;

    //用户增加申请表的方法
    @PostMapping("/audit/add")
    public Result add(@RequestBody Audit audit) {
        auditService.add(audit);
        return Result.success();
    }

    //管理员查申请信息
    @GetMapping("/audit/search")
    public Result search(Params params) {
        PageInfo<Audit> info = auditService.getBySearch(params);
        return Result.success(info);
    }

    //管理员编辑申请信息(审核)
    @PostMapping("/audit/check")
    public Result check(@RequestBody Audit audit) {
        auditService.check(audit);
        return Result.success();

    }

    //用户查自己的申请信息
    @GetMapping("/audit/{applyUserId}")
    public Result getMyAudit(@PathVariable Integer applyUserId) {
        List<Audit> myAudit = auditService.getMyAudit(applyUserId);
        return Result.success(myAudit);
    }

    //显示要领养的宠物信息
    @GetMapping("/audits/{petId}")
    public Result getAPet(@PathVariable Integer petId) {
        Audit pet = auditService.getAPet(petId);
        return Result.success(pet);
    }

    //用户删除申请信息
    @DeleteMapping("/delete/{auditId}")
    public Result delete(@PathVariable Integer auditId) {
        auditService.delete(auditId);
        return Result.success();
    }

    //用户修改领养申请
    @PostMapping("/audit/update")
    public Result update(@RequestBody Audit audit) {
        auditService.update(audit);
        return Result.success();
    }

    //用户查所有的领养申请
    @GetMapping("/audit/getReceive/{originalOwnerId}")
    public Result getAll(@PathVariable Integer originalOwnerId) {
        List<Audit> list = auditService.getReceive(originalOwnerId);
        return Result.success(list);
    }

    //用户修改宠物的领养状态

    @PostMapping("/audit/confirm")
    public Result setStatus(@RequestBody Pet pet) {
        auditService.setPet(pet);
        auditService.setProgress();
        return Result.success();
    }

    @PostMapping("audit/userAudit")
    //用户修改审核状态
    public Result setApplySta(@RequestBody Audit audit) {
        auditService.check(audit);
        return Result.success();
    }
}
